package com.example.myactspringboot.controller.exportZip;

import com.example.myactspringboot.server.ExportZIPService;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * @Author Zhouchb
 * @Create 2024-04-18 21:00
 * @Description
 */
@RestController
@RequestMapping("/zip")
public class ExportZipController {
    @Autowired
    private ExportZIPService service;

    //	#调用数据，然后传递给创建文件方法进行实现:
    /**
     * 打包佐证成果文件，压缩成为压缩包!
     *

     */
   // @ApiOperation(value = "打包佐证成果文件", notes = "佐证与成果-打包佐证成果文件")
    @GetMapping("/exportZip")
    public void exportZip(HttpServletResponse response) throws IOException {
        FileOutputStream outputStream = new FileOutputStream("E:\\新建文件夹\\12.zip");
        service.toZip("E:\\新建文件夹\\1713450824259",outputStream,true);
        FileInputStream fileInputStream = new FileInputStream("E:\\新建文件夹\\12.zip");
        service.downloadFile(response,"12.zip",fileInputStream);
        File file = new File("E:\\新建文件夹\\12.zip");
        File file1 = new File("E:\\新建文件夹\\1713450824259");
        service.deleteFile(file);
        service.deleteFile(file1);
    }

}
